package com.youan.serve.service.impl;

import com.youan.serve.dao.domain.Email;
import com.youan.serve.dao.domain.User;
import com.youan.serve.dao.idao.EmailMapper;
import com.youan.serve.service.IEmailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youan.serve.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author auto_code
 * @since 2020-03-10
 */
@Service
public class EmailServiceImpl extends ServiceImpl<EmailMapper, Email> implements IEmailService {
    @Autowired
    private IUserService iUserService;

    @Override
    public List<Email> setName(List<Email> emails) throws Exception {
        if(emails!=null && emails.size()>0){
            List<User> userList = iUserService.list();
            for(Email email : emails){
                for(User user : userList){
                    if(email.getSendUserId().equals(user.getUserId())){
                        email.setSendUserName(user.getUserName());
                    }
                    if(email.getReceiveUserId().equals(user.getUserId())){
                        email.setReceiveUserName(user.getUserName());
                    }
                }
            }
        }
        return emails;
    }
}
